package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IFamilyDao;
import com.hy.erp.inventory.pojo.Family;
import com.hy.erp.inventory.pojo.interfaces.IFamily;
import com.hy.erp.inventory.service.interfaces.IFamilyService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:18:23</li>
 * <li>类型名称：FamilyService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "familyService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class FamilyService extends AbstractBusinessService < IFamily> implements IFamilyService{

	@Override
	public String[] addFamily(Object[] family) {


		if ( null == family)
		{
			return null ;
		}
		
		else
		{
			

			IFamilyDao familyDao =
			                       ( IFamilyDao ) this
			                                          .getDao ( IFamily.class ) ;

			Family[] familys=new Family[family.length];
						for(int i=0;i<family.length;i++)
						{
							Family family2=( Family ) family[i];
							familys[i]=family2;
						}
						return familyDao
						                .persist ( familys ) ;


		}
		
	
	
	
	
	
	
	
	}

	@Override
	public boolean modifyFamily(IFamily family) {







		if ( ( null == family )
			     || ( null == family
			                                .getIdentifier ( ) )
			     || ( family
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{

				IFamilyDao familyDao =
                    ( IFamilyDao ) this
                                       .getDao ( IFamily.class ) ;
	                                        
		
					
				if ( null == family )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (familyDao
				                  .merge ( family ) != null ) ;
			}
		
	
	
	
	
	
	
	
	}

	@Override
	public Integer removeFamily(String[] familyIds) {







		if ( ( null == familyIds)
			     || ( familyIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{




				IFamilyDao familyDao =
                    ( IFamilyDao ) this
                                       .getDao ( IFamily.class ) ;
		

				return familyDao
				                .remove ( familyIds ) ;
			}
	
	
	
	
	
	
	
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public List < IFamily > getFamilyById (
											String [ ] Id )
	{
		if((Id.length!=0)||(Id!=null))
		{
			IFamilyDao familyDao =
                ( IFamilyDao ) this
                                   .getDao ( IFamily.class ) ;
		    return familyDao.findByIdentifier ( Id );
		}
		return null ;
	}

	@ Override
	public List < IFamily > getAllFamily ( )
	{

		IFamilyDao familyDao =
            ( IFamilyDao ) this
                               .getDao ( IFamily.class ) ;


		return familyDao
		                .find ( ) ;
	}

	@ Override
	public List < IFamily > getFamilyByQueryName (
													String queryName ,
													Object [ ] args )
	{
		IFamilyDao familyDao =
            ( IFamilyDao ) this
                               .getDao ( IFamily.class ) ;


		return familyDao
		                .findByNamedQuery ( queryName , args );
	}

	@ Override
	public String [ ] modifyFamily (
										Object [ ] family )
	{



		if ( null == family)
		{
			return null ;
		}
		
		else
		{
			

			IFamilyDao familyDao =
			                       ( IFamilyDao ) this
			                                          .getDao ( IFamily.class ) ;

			Family[] familys=new Family[family.length];
						for(int i=0;i<family.length;i++)
						{
							Family family2=( Family ) family[i];
							familys[i]=family2;
						}
						return familyDao
						                .merge ( familys ) ;


		}
	
	
	}

}
